package vn.aptech.leaveManagementSystem.business.model;

import java.sql.CallableStatement;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.naming.spi.DirStateFactory.Result;

import vn.aptech.leaveManagementSystem.business.dto.Holiday;
import vn.aptech.leaveManagementSystem.dao.DBManager;

public class Holidays extends DBManager{
	
	public int addHoliday(Holiday hol) throws SQLException
	{
		getConn();
		String sql="{Call sp_InsertHoliday(?,?,?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setDate(1, hol.getStartDate());
		cs.setDate(2, hol.getEndDate());
		cs.setString(3, hol.getEvent());
		return cs.executeUpdate();
	}
	
	public int updateHoliday(Holiday hol) throws SQLException
	{
		getConn();
		String sql="{Call sp_UpdateHoliday(?,?,?,?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setInt(1, hol.getIDHoliday());
		cs.setDate(2, hol.getStartDate());
		cs.setDate(3, hol.getEndDate());
		cs.setString(4, hol.getEvent());
		return cs.executeUpdate();
	}
	
	public int deleteHoliday(int idHol) throws SQLException
	{
		getConn();
		String sql="{Call sp_DeleteHoliday(?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setInt(1, idHol);
		return cs.executeUpdate();
	}
	
	public ResultSet getHoliday(int idHol) throws SQLException
	//Holiday.IDHoliday, Holiday.StartDate,Holiday.EndDate,Holiday.Event
	{
		getConn();
		String sql="{Call sp_getHoliday(?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setInt(1, idHol);
		ResultSet rs=cs.executeQuery();
		return rs;
	}
	
	public ResultSet getHolidayList() throws SQLException
	//Holiday.IDHoliday, Holiday.StartDate,Holiday.EndDate,Holiday.Event
	{
		getConn();
		String sql="{Call sp_getHolidayList}";
		CallableStatement cs=conn.prepareCall(sql);
		ResultSet rs=cs.executeQuery();
		return rs;
	}
	
	public ResultSet getUpcomingHolidays() throws SQLException
	{
		java.util.Date currentDate=new java.util.Date();
		Date date=new Date(currentDate.getYear(), currentDate.getMonth(), currentDate.getDay());
		getConn();
		String sql="{Call sp_getUpcomingHolidays(?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setDate(1,date);
		ResultSet rs=cs.executeQuery();
		return rs;
	}
	
}
